from pynput.keyboard import Listener, Key
KEY = Key.f8

def on_press(key):
    print(f"按下键: {key}")
    if key == KEY:
        print("F8键被按下")

def on_release(key):
    print(f"松开键: {key}")
    if key == KEY:
        print("F8键被松开")
    if key == Key.esc:
        return False


if __name__ == "__main__":
    with Listener(on_press=on_press, on_release=on_release) as listener:
        listener.join()